home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / programr / appsrcs.zip / APPMORE.ZIP / APPTOOLS.C < prev    next >
C/C++ Source or Header  |  1993-04-08  |  16KB  |  444 lines

  1. #define STRICT
  2. #include <windows.h>
  3. #include <windowsx.h>
  4. #include <shellapi.h>
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <string.h>
  8. #include "appmore.h"
  9.  
  10. char WindowsDir[MAXFILECHARS];
  11.  
  12. /*----------------------------------------------------------------------------*/
  13. /* FUNCTION: OkMsgBox(char *szCaption, char *szFormat, ...)             */
  14. /*                                                                            */
  15. /* PURPOSE:  Display in an OKmessageBox a given text                       */
  16. /*----------------------------------------------------------------------------*/
  17. VOID OkMsgBox(char *szCaption, char *szFormat, ...)
  18.     {
  19.     char szBuffer[256];
  20.     char *pArguments;
  21.  
  22.     pArguments = (char *) &szFormat + sizeof(szFormat);
  23.     vsprintf(szBuffer, szFormat, pArguments);
  24.     if(AppSound.EnableSound != 0)
  25.     if(stricmp(AppSound.ErrorMessage, "<none>") != 0)
  26.         sndPlaySound(AppSound.ErrorMessage, SND_ASYNC | SND_NODEFAULT);
  27.     MessageBox(NULL, szBuffer, szCaption, MB_OK);
  28.     }
  29.  
  30. /*----------------------------------------------------------------------------*/
  31. /* FUNCTION: ErrorMsgBox(char *szCaption, char *szFormat, ...)             */
  32. /*                                                                            */
  33. /* PURPOSE:  Display in an ErrormessageBox a given text                       */
  34. /*----------------------------------------------------------------------------*/
  35. VOID ErrorMsgBox(char *szCaption, char *szFormat, ...)
  36.     {
  37.     char szBuffer[256];
  38.     char *pArguments;
  39.  
  40.     pArguments = (char *) &szFormat + sizeof(szFormat);
  41.     vsprintf(szBuffer, szFormat, pArguments);
  42.     if(AppSound.EnableSound != 0)
  43.     if(stricmp(AppSound.ErrorMessage, "<none>") != 0)
  44.         sndPlaySound(AppSound.ErrorMessage, SND_ASYNC | SND_NODEFAULT);
  45.     MessageBox(NULL, szBuffer, szCaption, MB_OK | MB_ICONEXCLAMATION);
  46.     }
  47.  
  48. /*--------------------------------------------------------------------------*/
  49. APPMAXSIZE CalculateAppMaxSize(VOID)
  50.     {
  51.     int xScreen, yScreen, xAppBar, yAppBar;
  52.     DWORD xMax = 0, yMax = 0;
  53.     APPMAXSIZE AppBarSize, AppSizeX, AppSizeY;
  54.  
  55.    xScreen = GetSystemMetrics(SM_CXSCREEN);
  56.    yScreen = GetSystemMetrics(SM_CYSCREEN);
  57.    if(AppSystem.Left == -1)
  58.     xAppBar = xScreen - (AppWindow.cxButton*(AppWindow.nColumns+1));
  59.     else
  60.     xScreen = AppSystem.Left;
  61.     if(AppSystem.Top == -1)
  62.     yAppBar = yScreen - (AppWindow.cyButton*(AppWindow.nButtons/AppWindow.nColumns));
  63.     else
  64.     yAppBar = AppSystem.Top;
  65.  
  66.     // calculate the size of AppBar.
  67.     AppBarSize.left = xAppBar;
  68.     AppBarSize.top = yAppBar;
  69.     AppBarSize.width = AppWindow.cxButton*AppWindow.nColumns;
  70.     AppBarSize.height = AppWindow.cyButton*(AppWindow.nButtons/AppWindow.nColumns);
  71.  
  72.     // determine largest left space in X direction
  73.     if(AppBarSize.left >= (xScreen -(AppBarSize.left+AppBarSize.width)))
  74.     {
  75.     // largest x-space is to the left of AppBar
  76.     xMax = AppBarSize.left;
  77.     AppSizeX.left = 0;
  78.     AppSizeX.top = 0;
  79.     AppSizeX.width = AppBarSize.left;
  80.     AppSizeX.height = yScreen;
  81.     }
  82.     else
  83.     {
  84.     // largest x-space is to the right of AppBar
  85.     xMax = (xScreen -(AppBarSize.left+AppBarSize.width));
  86.     AppSizeX.left = AppBarSize.left + AppBarSize.width;
  87.     AppSizeX.top = 0;
  88.     AppSizeX.width = xScreen -(AppBarSize.left+AppBarSize.width);
  89.     AppSizeX.height = yScreen;
  90.     }
  91.     if(AppBarSize.top >= (yScreen -(AppBarSize.top+AppBarSize.height)))
  92.     {
  93.     // largest y-space is above AppBar
  94.     yMax = AppBarSize.top;
  95.     AppSizeY.left = 0;
  96.     AppSizeY.top = 0;
  97.     AppSizeY.width = xScreen;
  98.     AppSizeY.height = AppBarSize.top;
  99.     }
  100.     else
  101.     {
  102.     // largest y-space is under AppBar
  103.     yMax = (yScreen -(AppBarSize.top+AppBarSize.height));
  104.     AppSizeY.left = 0;
  105.     AppSizeY.top = AppBarSize.top + AppBarSize.height;
  106.     AppSizeY.width = xScreen;
  107.     AppSizeY.height = yScreen - (AppBarSize.top+AppBarSize.height);
  108.     }
  109.  
  110.     xMax *= yScreen;
  111.     yMax *= xScreen;
  112.     if(xMax >= yMax)
  113.     return AppSizeX;
  114.     else
  115.     return AppSizeY;
  116.     }
  117.  
  118. /*--------------------------------------------------------------------------*/
  119. TEXTMETRIC RetrieveTextMetrics(HWND hWnd)
  120.     {
  121.     int iOldMapMode;
  122.     HDC hDC;
  123.     TEXTMETRIC tm;
  124.  
  125.     hDC = GetDC(hWnd);
  126.     iOldMapMode = GetMapMode(hDC);
  127.     SetMapMode(hDC, MM_TEXT);
  128.     SelectFont(hDC, GetStockFont(SYSTEM_FONT));
  129.     GetTextMetrics(hDC, &tm);
  130.     SetMapMode(hDC, iOldMapMode);
  131.     DeleteDC(hDC);
  132.     return tm;
  133.     }
  134.  
  135. /*------------------------------------------------------------------------*/
  136. int VerifySectionName(LPSTR SectionName)
  137.     {
  138.     int i;
  139.     char IniString[20];
  140.  
  141.     GetPrivateProfileString(INI_APPMORE, NUMBEROFSECTIONS, SECTIONS_DEFAULT,
  142.                 szBuffer, MAXDIGITS, INI_FILE);
  143.     AppSystem.NumberOfSections = atoi(szBuffer);
  144.     AppSystem.NumberOfSections = max(AppSystem.NumberOfSections, 0);
  145.  
  146.     if(AppSystem.NumberOfSections == 0)
  147.     return 0;
  148.  
  149.     for(i=0;i<AppSystem.NumberOfSections;i++)
  150.     {
  151.     sprintf(IniString,"%d",i+1);
  152.     GetPrivateProfileString(INI_APPMORE, IniString, SECTIONNAME_DEFAULT,
  153.                 szBuffer, MAXFILECHARS-1, INI_FILE);
  154.     if(strcmp(szBuffer,SectionName) == 0)
  155.         return (i+1);
  156.     }
  157.     return 0;
  158.     }
  159.  
  160. /*--------------------------------------------------------------------------*/
  161. VOID InitDefaultButton(VOID)
  162.     {
  163.     char ReadString[MAXDIGITS];
  164.  
  165.     GetWindowsDirectory(WindowsDir, MAXFILECHARS);
  166.  
  167.     strcpy(AppButtonDefault.IcoName, "");
  168.     strcpy(AppButtonDefault.ProgName, "");
  169.     strcpy(AppButtonDefault.Params, "");
  170.     strcpy(AppButtonDefault.StartDir, "");
  171.     AppButtonDefault.IconNumber = 0;
  172.     AppButtonDefault.ButtonLook = 0;
  173.     AppButtonDefault.Close = TRUE;
  174.     AppButtonDefault.ShowMode = 0;
  175.  
  176.     AppSound.EnableSound = 0;
  177.     strcpy(AppSound.ProgramStart, PROGSTART_DEFAULT);
  178.     strcpy(AppSound.ProgramClose, PROGCLOSE_DEFAULT);
  179.     strcpy(AppSound.DropFile, DROPFILE_DEFAULT);
  180.     strcpy(AppSound.ErrorMessage, ERRORMESSAGE_DEFAULT);
  181.  
  182.     GetPrivateProfileString(INI_APPMORE, INITIALIZED, INITIALIZED_DEFAULT,
  183.                 ReadString, MAXDIGITS, INI_FILE);
  184.     AppSystem.Initialized = atoi(ReadString);
  185.     AppSystem.Initialized = max(AppSystem.Initialized, 0);
  186.     }
  187.  
  188. /*--------------------------------------------------------------------------*/
  189. /* FUNCTION: IniRead(void)                            */
  190. /*                                        */
  191. /* PURPOSE:  Read settings in the appbar.ini file.                */
  192. /*--------------------------------------------------------------------------*/
  193. VOID PASCAL IniRead(VOID)
  194.     {
  195.     char ReadString[MAXDIGITS],IniString[20];
  196.     char SystemSection[256], ButtonSection[256], SoundSection[256];
  197.     int i, CloseProg;
  198.  
  199.     SetCursor(LoadCursor(NULL, IDC_WAIT));
  200.  
  201.     if(AppSystem.SectionNumber == 0)
  202.     {
  203.     for(i=0;i<MAXAPPS;i++)
  204.         AppButton[i] = AppButtonDefault;
  205.     strcpy(AppSystem.SectionName, "<none>");
  206.     SetCursor(LoadCursor(NULL, IDC_ARROW));
  207.     return;
  208.     }
  209.  
  210.     sprintf(IniString,"%d", AppSystem.SectionNumber);
  211.     GetPrivateProfileString(INI_APPMORE, IniString, SECTIONNAME_DEFAULT,
  212.                 AppSystem.SectionName, MAXFILECHARS-1, INI_FILE);
  213.  
  214.     // get ini-settings for AppSystem struct.
  215.     strcpy(SystemSection, AppSystem.SectionName);
  216.     strcat(SystemSection, "_System");
  217.     strcpy(ButtonSection, AppSystem.SectionName);
  218.     strcat(ButtonSection, "_Buttons");
  219.     strcpy(SoundSection, AppSystem.SectionName);
  220.     strcat(SoundSection, "_Sounds");
  221.  
  222.     // get ini-settings for AppSystem struct.
  223.     GetPrivateProfileString(SystemSection, LEFT, LEFT_DEFAULT, ReadString,
  224.                 MAXDIGITS, INI_FILE);
  225.  
  226.     AppSystem.Left = atoi(ReadString);
  227.     AppSystem.Left = max(AppSystem.Left, -1);
  228.     AppSystem.Left = min(AppSystem.Left, MAXRES);
  229.  
  230.     GetPrivateProfileString(SystemSection, TOP, TOP_DEFAULT, ReadString,
  231.             MAXDIGITS, INI_FILE);
  232.     AppSystem.Top = atoi(ReadString);
  233.     AppSystem.Top = max(AppSystem.Top, -1);
  234.     AppSystem.Top = min(AppSystem.Top, MAXRES);
  235.  
  236.     GetPrivateProfileString(SystemSection, BUTTONS, BUTTONS_DEFAULT, ReadString,
  237.             MAXDIGITS, INI_FILE);
  238.     AppSystem.Buttons = atoi(ReadString);
  239.     AppSystem.Buttons = max(AppSystem.Buttons, 0);
  240.     AppSystem.Buttons = min(AppSystem.Buttons, MAXAPPS);
  241.  
  242.     GetPrivateProfileString(SystemSection, COLUMNS, COLUMNS_DEFAULT, ReadString,
  243.             MAXDIGITS, INI_FILE);
  244.     AppSystem.Columns = atoi(ReadString);
  245.     AppSystem.Columns = max(AppSystem.Columns, 1);
  246.     AppSystem.Columns = min(AppSystem.Columns, AppSystem.Buttons+2);
  247.  
  248.     GetPrivateProfileString(SystemSection, ONELAUNCH, ONELAUNCH_DEFAULT,
  249.             ReadString, MAXDIGITS, INI_FILE);
  250.     AppSystem.OneLaunch    = atoi(ReadString);
  251.     AppSystem.OneLaunch = max(AppSystem.OneLaunch, 0);
  252.     AppSystem.OneLaunch = min(AppSystem.OneLaunch, 1);
  253.  
  254.     GetPrivateProfileString(SystemSection, CLOSEALL, CLOSEALL_DEFAULT,
  255.             ReadString, MAXDIGITS, INI_FILE);
  256.     AppSystem.CloseAll = atoi(ReadString);
  257.     AppSystem.CloseAll = max(AppSystem.CloseAll, 0);
  258.     AppSystem.CloseAll = min(AppSystem.CloseAll, 1);
  259.  
  260.     GetPrivateProfileString(SystemSection, DOUBLECLICK, DOUBLECLICK_DEFAULT,
  261.             ReadString, MAXDIGITS, INI_FILE);
  262.     AppSystem.DoubleClick = atoi(ReadString);
  263.     AppSystem.DoubleClick = max(AppSystem.DoubleClick, 0);
  264.     AppSystem.DoubleClick = min(AppSystem.DoubleClick, 1);
  265.  
  266.     GetPrivateProfileString(SystemSection, STAYINFRONT, STAYINFRONT_DEFAULT,
  267.             ReadString, MAXDIGITS, INI_FILE);
  268.     AppSystem.StayInFront = atoi(ReadString);
  269.     AppSystem.StayInFront = max(AppSystem.StayInFront, 0);
  270.     AppSystem.StayInFront = min(AppSystem.StayInFront, 1);
  271.  
  272.     GetPrivateProfileString(SoundSection, SOUNDENABLE, SOUNDENABLE_DEFAULT,
  273.             ReadString, MAXDIGITS, INI_FILE);
  274.     AppSound.EnableSound = atoi(ReadString);
  275.     AppSound.EnableSound = max(AppSound.EnableSound, 0);
  276.     AppSound.EnableSound = min(AppSound.EnableSound, 1);
  277.  
  278.     GetPrivateProfileString(SoundSection, PROGSTART, PROGSTART_DEFAULT,
  279.         AppSound.ProgramStart, MAXFILECHARS-1, INI_FILE);
  280.  
  281.     GetPrivateProfileString(SoundSection, PROGCLOSE, PROGCLOSE_DEFAULT,
  282.         AppSound.ProgramClose, MAXFILECHARS-1, INI_FILE);
  283.  
  284.     GetPrivateProfileString(SoundSection, DROPFILE, DROPFILE_DEFAULT,
  285.         AppSound.DropFile, MAXFILECHARS-1, INI_FILE);
  286.  
  287.     GetPrivateProfileString(SoundSection, ERRORMESSAGE, ERRORMESSAGE_DEFAULT,
  288.         AppSound.ErrorMessage, MAXFILECHARS-1, INI_FILE);
  289.  
  290.     // get settings for AppButon struct.
  291.     for(i=0;i<MAXAPPS;i++)
  292.     {
  293.     AppButton[i] = AppButtonDefault;
  294.     sprintf(IniString,"Icon%d",i+1);
  295.     GetPrivateProfileString(ButtonSection, IniString, AppButton[i].IcoName,
  296.                 AppButton[i].IcoName, MAXFILECHARS-1, INI_FILE);
  297.  
  298.     sprintf(IniString,"Prog%d",i+1);
  299.     GetPrivateProfileString(ButtonSection, IniString, WindowsDir,
  300.                 AppButton[i].ProgName, MAXFILECHARS-1, INI_FILE);
  301.  
  302.     sprintf(IniString,"Dir%d",i+1);
  303.     GetPrivateProfileString(ButtonSection, IniString, AppButton[i].StartDir,
  304.                 AppButton[i].StartDir, MAXFILECHARS-1, INI_FILE);
  305.  
  306.     sprintf(IniString,"Params%d",i+1);
  307.     GetPrivateProfileString(ButtonSection, IniString, AppButton[i].Params,
  308.                 AppButton[i].Params, MAXFILECHARS-1, INI_FILE);
  309.  
  310.     sprintf(IniString,"Close%d",i+1);
  311.     GetPrivateProfileString(ButtonSection, IniString, CLOSEPROG_DEFAULT,
  312.                 ReadString, MAXDIGITS, INI_FILE);
  313.     CloseProg = atoi(ReadString);
  314.     CloseProg = (CloseProg > 0) ? CloseProg : 0;
  315.     CloseProg = (CloseProg < 1) ? CloseProg : 1;
  316.     if(CloseProg == 1)
  317.         AppButton[i].Close = TRUE;
  318.     else
  319.         AppButton[i].Close = FALSE;
  320.     if(AppSystem.CloseAll == 0)
  321.         AppButton[i].Close = FALSE;
  322.  
  323.     sprintf(IniString,"ShowMode%d",i+1);
  324.     GetPrivateProfileString(ButtonSection, IniString, SHOWMODE_DEFAULT,
  325.                 ReadString, MAXDIGITS, INI_FILE);
  326.     AppButton[i].ShowMode = atoi(ReadString);
  327.     AppButton[i].ShowMode = max(AppButton[i].ShowMode, 0);
  328.     AppButton[i].ShowMode = min(AppButton[i].ShowMode, 3);
  329.  
  330.     sprintf(IniString,"IconNumber%d",i+1);
  331.     GetPrivateProfileString(ButtonSection, IniString, ICONNUMBER_DEFAULT,
  332.                 ReadString, MAXDIGITS, INI_FILE);
  333.     AppButton[i].IconNumber = atoi(ReadString);
  334.     AppButton[i].IconNumber = max(AppButton[i].IconNumber, 0);
  335.  
  336.     sprintf(IniString,"ButtonLook%d",i+1);
  337.     GetPrivateProfileString(ButtonSection, IniString, BUTTONLOOK_DEFAULT,
  338.                 ReadString, MAXDIGITS, INI_FILE);
  339.     AppButton[i].ButtonLook = atoi(ReadString);
  340.     AppButton[i].ButtonLook = max(AppButton[i].ButtonLook, 0);
  341.     AppButton[i].ButtonLook = min(AppButton[i].ButtonLook, 1);
  342.     }
  343.     SetCursor(LoadCursor(NULL, IDC_ARROW));
  344.     }
  345.  
  346. /*--------------------------------------------------------------------------*/
  347. VOID PASCAL SaveButton(int i)
  348.     {
  349.     char SaveString[MAXDIGITS], IniString[20];
  350.     char ButtonSection[256];
  351.  
  352.     strcpy(ButtonSection, AppSystem.SectionName);
  353.     strcat(ButtonSection, "_Buttons");
  354.  
  355.     sprintf(IniString,"Icon%d",i+1);
  356.     WritePrivateProfileString(ButtonSection, IniString, AppButton[i].IcoName, INI_FILE);
  357.     sprintf(IniString,"Prog%d",i+1);
  358.     WritePrivateProfileString(ButtonSection, IniString, AppButton[i].ProgName, INI_FILE);
  359.     sprintf(IniString,"Dir%d",i+1);
  360.     WritePrivateProfileString(ButtonSection, IniString, AppButton[i].StartDir, INI_FILE);
  361.     sprintf(IniString,"Params%d",i+1);
  362.     WritePrivateProfileString(ButtonSection, IniString, AppButton[i].Params, INI_FILE);
  363.     sprintf(IniString,"Close%d",i+1);
  364.     sprintf(SaveString,"%d",AppButton[i].Close);
  365.     WritePrivateProfileString(ButtonSection, IniString, SaveString, INI_FILE);
  366.     sprintf(IniString,"ShowMode%d",i+1);
  367.     sprintf(SaveString,"%d",AppButton[i].ShowMode);
  368.     WritePrivateProfileString(ButtonSection, IniString, SaveString, INI_FILE);
  369.     sprintf(IniString,"IconNumber%d",i+1);
  370.     sprintf(SaveString,"%d",AppButton[i].IconNumber);
  371.     WritePrivateProfileString(ButtonSection, IniString, SaveString, INI_FILE);
  372.     sprintf(IniString,"ButtonLook%d",i+1);
  373.     sprintf(SaveString,"%d",AppButton[i].ButtonLook);
  374.     WritePrivateProfileString(ButtonSection, IniString, SaveString, INI_FILE);
  375.     }
  376.  
  377. /*-------------------------------------------------------------------------*/
  378. VOID SetNormalChildCursor(VOID)
  379.     {
  380.     SetClassWord(hWndButton[0], GCW_HCURSOR,
  381.          LoadCursor(NULL, IDC_ARROW));
  382.     }
  383.  
  384. /*-------------------------------------------------------------------------*/
  385. VOID SetShuffleChildCursor(VOID)
  386.     {
  387.     SetClassWord(hWndButton[0], GCW_HCURSOR,
  388.          LoadCursor(hInst, "AppShuffle"));
  389.     }
  390.  
  391. /*-------------------------------------------------------------------------*/
  392. void LoadAllButtonIcons(HICON *hIcon)
  393.     {
  394.     int i;
  395.  
  396.     for(i=0;i<AppSystem.Buttons;i++)
  397.     {
  398.     hIcon[i] = ExtractIcon(hInst, AppButton[i].IcoName, AppButton[i].IconNumber);
  399.     if(hIcon[i] == (HICON) 1)
  400.         {
  401.         hIcon[i] = NULL;
  402.         OkMsgBox("AppMore - Initialisation", "No Icons found in %s", AppButton[i].IcoName);
  403.         }
  404.     }
  405.     }
  406. /*-------------------------------------------------------------------------*/
  407. void LoadAppMoreResources(void)
  408.     {
  409.     hAppLogo   = LoadBitmap(hInst, "AppLogo");
  410.     hNNever    = LoadBitmap(hInst, "NNever");
  411.     hQuickLoad = LoadIcon(hInst, MAKEINTRESOURCE(1005));
  412.  
  413.     if(!AppSystem.BigButtons)
  414.     {
  415.     hSystem       = LoadIcon(hInst, MAKEINTRESOURCE(1000));
  416.     hPressed   = LoadIcon(hInst, MAKEINTRESOURCE(1004));
  417.     hBlank       = LoadIcon(hInst, MAKEINTRESOURCE(1003));
  418.     hKeybOn       = LoadIcon(hInst, MAKEINTRESOURCE(1006));
  419.     }
  420.  
  421.     if(AppSystem.BigButtons)
  422.     {
  423.     hSystem2  = LoadIcon(hInst, MAKEINTRESOURCE(1008));
  424.     hPressed2 = LoadIcon(hInst, MAKEINTRESOURCE(1007));
  425.     hbBlank   = LoadBitmap(hInst, "BlankBMP");
  426.     hbKeyb      = LoadBitmap(hInst, "KeybBMP");
  427.     hbPressed = LoadBitmap(hInst, "PressBMP");
  428.     }
  429.     }
  430.  
  431. /*-------------------------------------------------------------------------*/
  432. void FreeAppMoreResources(void)
  433.     {
  434.     DeleteBitmap(hAppLogo);
  435.     DeleteBitmap(hNNever);
  436.  
  437.     if(AppSystem.BigButtons)
  438.     {
  439.     DeleteBitmap(hbBlank);
  440.     DeleteBitmap(hbKeyb);
  441.     DeleteBitmap(hbPressed);
  442.     }
  443.     }
  444.